/*============================================================================*/
/*                   CONTINENTAL AUTOMOTIVE SYSTEMS                           */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* name:            APPLigth.c
* version:         1.0
* created_by:      Continental
* date_created:    Ago 11 2011
*=============================================================================*/
/* DESCRIPTION : Source file for Application layer for WHEEL                  */
/*============================================================================*/
/* FUNCTION COMMENT : Describes the functions for Application Layer for WHEEL */
/* Include the state machine for WHEEL                                        */
/*============================================================================*/
/*                               OBJECT HISTORY                               */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1.0      | 11/ago/2011 |                               | Continental      */
/* Initial version for the Smart Car Race 2010 contest using Freescale        */
/* Bolero micro.                                                              */
/*============================================================================*/


#include "HALLedCtrl.h"


uint16_t AppFlag=0;
static uint16_t counter=0;

 void SM_WL(uint16_t e_sm_wl)
{
	switch(e_sm_wl)
	{
		case LED_OFF:
		{
			Ports_Ledwait();
			vfnPorts_Led0();
			break;
		}
		
		case LED_1:
		{
			Ports_Ledwait();
			vfnPorts_Led1();
			break;
		}
		
		case LED_2:
		{
			Ports_Ledwait();
			vfnPorts_Led2();
			break;
		}
		case LED_3:
		{
			Ports_Ledwait();
			vfnPorts_Led3();
			break;
		}
		
		case LED_4:
		{
			Ports_Ledwait();
			vfnPorts_Led4();
			break;
		}
		
		case  LED_5:
		{
			Ports_Ledwait();
			vfnPorts_Led5();
			break;
		}
		case LED_6:
		{
			Ports_Ledwait();
			vfnPorts_Led6();
			break;
		}
		
		case LED_7:
		{
			Ports_Ledwait();
			vfnPorts_Led7();
			break;
		}
		
		case LED_8:
		{
			Ports_Ledwait();
			vfnPorts_Led8();
			break;
		}
		case LED_9:
		{
			Ports_Ledwait();
			vfnPorts_Led9();
			break;
		}
		case LED_ON:
		{
			Ports_Ledwait();
			vfnPorts_Led10();
			break;
		}
		default:
			break;
	}
}


void Delay_5s(void)
{
uint16_t i,j;	
	for(i=0; i< 11000 ; i++)
	{
		for(j=0; j<6000; j++){}
	}
	AppFlag=FALSE;		
}


void LedCtrl_AUP(void)
{
	counter++;
	if (counter>LED_ON)
	{
		AppFlag2=TRUE;
	}
	else
	{
		SM_WL(counter);
	}

	
}


void LedCtrl_ADOWN(void)
{

	if (counter>LED_OFF)
	{
		counter--;
		SM_WL(counter);
	}
	else
	{
		SM_WL(counter);
		AppFlag2=TRUE;
	}

	
}


void LedCtril_NormalUP(void)
{
	if (counter==LED_ON)
	{
		SM_WL(LED_ON);
	}
	else
	{
		if (counter<LED_ON)
		{
			counter+=1;
			SM_WL(counter);
		}
	}
	
	AppFlag2=TRUE;

}

void LedCtril_NormalDOWN(void)
{	
	if (counter==LED_OFF)
	{
		counter=0;
		SM_WL(counter);
	}
	else
	{
		if (counter>LED_OFF)
		{
			counter-=1;
			SM_WL(counter);
		}
	}
	AppFlag2=TRUE;	
}


void LedCtrl_PINCHDOWN(void)
{
	while(counter>FALSE)
	{
		counter--;
		SM_WL(counter);
	}
	SM_WL(counter);
}